#include "dlgpcaphub.h"
#include <QApplication>
#include <QLocale>
#include <QFile>
#include <QTranslator>
#include "io/pcapio.h"
#include "tb_interface/cmdlineparser.h"
#include "tb_interface/tb_interface.h"
const bool TASKBUSDBG = false;
using namespace TASKBUS;
int main(int argc, char *argv[])
{
	QApplication a(argc, argv);
	init_client();
	cmdlineParser args;
	//Debug
	if (TASKBUSDBG)
	{
		auto cmdline = TASKBUS::debug("d:/log/pid2837",0,0);
		args.parser(cmdline);
	}
	else
		args.parser(argc,argv);

	int ret = 0;
	//Arg--information参数,打印自己的功能定义字符串。
	if (args.contains("information"))
	{
		QFile fp(":/tb_interface/interface.json");
		if (fp.open(QIODevice::ReadOnly))
		{
			QByteArray arr = fp.readAll();
			arr.push_back('\0');
			puts(arr.constData());
			fflush(stdout);
		}
	}
	else
	{
		QTranslator translator;
		const QStringList uiLanguages = QLocale::system().uiLanguages();
		for (const QString &locale : uiLanguages) {
			const QString baseName = "pcapHub_" + QLocale(locale).name();
			if (translator.load(":/i18n/" + baseName)) {
				a.installTranslator(&translator);
				break;
			}
		}
		PCAPIO::init_buffer();
		DlgPCAPHub w(args);
		w.show();
		ret = a.exec();
	}
	return ret;
}
